package com.prs.crm.action.crm;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import com.prs.crm.domain.crm.DocumenTaryStyle;
import com.prs.crm.service.crm.DocumenTaryStyleService;

public class DocumenTaryStyleAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private DocumenTaryStyle documenTaryStyle;
	private DocumenTaryStyleService documenTaryStyleService;
	private Integer[] styleIds;
	
	@Action("listDocumenTaryStyle")
	public String listDocumenTaryStyle() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				DocumenTaryStyle.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.documenTaryStyleService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("editDocumenTaryStyle")
	public String editDocumenTaryStyle() {
		if(styleIds!=null){
			this.documenTaryStyle=this.documenTaryStyleService.get(styleIds[0]);
		}
		return SUCCESS;
	}
	@Action(value = "savebb", results = {
			@Result(name = "success", type = "redirect", location = "listDocumenTaryStyle"),
			@Result(name = "error", type = "chain", location = "listDocumenTaryStyle")})
	public String savebb(){
		this.documenTaryStyle=this.documenTaryStyleService.get(styleIds[0]);
		documenTaryStyle.setRemark("默认");
		this.documenTaryStyleService.submit(documenTaryStyle);
		return SUCCESS;
	}
	@Action(value = "saveqq", results = {
			@Result(name = "success", type = "redirect", location = "listDocumenTaryStyle"),
			@Result(name = "error", type = "chain", location = "listDocumenTaryStyle")})
	public String saveqq(){
		List<DocumenTaryStyle> list=this.documenTaryStyleService.getAllStyles();
		for(int i=0;i<list.size();i++){
			DocumenTaryStyle d=list.get(i);
			if(d.getRemark()!=null){
				d.setRemark("");
				this.documenTaryStyleService.submit(d);
			}
		}
		return SUCCESS;
	}
	@Action(value = "saveDocumenTaryStyle", results = {
			@Result(name = "success", type = "redirect", location = "listDocumenTaryStyle"),
			@Result(name = "error", type = "chain", location = "editDocumenTaryStyle")})
	public String saveCustomerDegree(){
		if(documenTaryStyle.getId()==null){
			this.documenTaryStyleService.save(documenTaryStyle);
		}else{
			this.documenTaryStyleService.submit(documenTaryStyle);
		}
		return SUCCESS;
	}
	@Action(value = "removeDocumenTaryStyle", results = {
			@Result(name = "success", type = "redirect", location = "listDocumenTaryStyle"),
			@Result(name = "error", type = "chain", location = "listDocumenTaryStyle")})
	public String removeDocumenTaryStyle(){
		this.documenTaryStyleService.batchRemove(styleIds);
		return SUCCESS;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public DocumenTaryStyle getDocumenTaryStyle() {
		return documenTaryStyle;
	}
	public void setDocumenTaryStyle(DocumenTaryStyle documenTaryStyle) {
		this.documenTaryStyle = documenTaryStyle;
	}
	public DocumenTaryStyleService getDocumenTaryStyleService() {
		return documenTaryStyleService;
	}
	public void setDocumenTaryStyleService(
			DocumenTaryStyleService documenTaryStyleService) {
		this.documenTaryStyleService = documenTaryStyleService;
	}

	public Integer[] getStyleIds() {
		return styleIds;
	}

	public void setStyleIds(Integer[] styleIds) {
		this.styleIds = styleIds;
	}
	
	
}
